package topic.dp;

/*
509 斐波纳契数列
 */
public class FIB {
    public static void main(String[] args) {

        System.out.println(method(3));
        System.out.println(fib(3));
    }

    // 递归
    public static int method(int n) {
        if (n < 2) return n;
        return method(n - 1) + method(n - 2);
    }

    public static int fib(int n) {
        /*

         */
        if (n < 2) return n;
        int[] dp = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;
        for (int i = 2; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        return dp[n];
    }
}
